/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.DateRangeFieldValidator;
import database.IssuingDAO;
import java.util.Date;
import java.util.List;
import java.util.Map;
import model.Issue;
import model.Order;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Trang
 */
@Namespace("/Administration/Issue")
public class IssueManagementAction extends ActionSupport{
    private List<Issue> issues;
    private Date startDate;
    
    private Date endDate;
     public List<Issue> getIssues() {
        return issues;
    }

    public void setIssues(List<Issue> issues) {
        this.issues = issues;
    }

    
    public IssuingDAO issueDAO = new IssuingDAO();

    public Date getStartDate() {
        return startDate;
    }

    @DateRangeFieldValidator(message = "Invalid Date", min = "01/01/1922", max = "12/31/2012")
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    @DateRangeFieldValidator(message = "Invalid Date", min = "01/01/1922", max = "12/31/2012")
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
    
     @Action(value = "issue-management", results = {
        @Result(name = "success", location = "/manageIssue/w_issue.jsp")
    })
    public String IssueManagement(){
          Map session = ActionContext.getContext().getSession();
                session.put("issue", 1);
                
        issues = issueDAO.getAllIssue();
        int[] idOrderOfIssue = new int[issues.size()]; 
        int index = 0;
        for(Issue item: issues)
        {
            //System.out.println("IDORder" + item.getIdOrder());
            idOrderOfIssue[index] = item.getOrder().getIdOrder();
            //status[index] = item.getOrderStatus();
            index ++;
        }
          session.put("idIssue", idOrderOfIssue);
          
        return SUCCESS;
    }
     
      @Action(value = "getIssue", results = {
        @Result(name = "success", location = "/manageIssue/w_issue.jsp")
    })
    public String GetIssue(){
          
        issues = issueDAO.getIssueBetweenDate(startDate, endDate);
                //.getAllIssue();
          
        return SUCCESS;
    }
}
